import http.client
conn = http.client.HTTPConnection("localhost")#建立服务器连接
conn.request("GET","/agileone/") #发送GET请求访问首页
setcookie = conn.getresponse().getheader("Set-Cookie")
# print(setcookie)
sessionid = setcookie.split(";")[0] #按；分隔并取出第一部分内容
print(sessionid) #确认正确获取到PHPSESSID字段

param = "username=admin&password=admin&savelogin=true"
#构建请求头，必须要将Cookie=sessionid的状态信息附加在请求中
header = {"Content-type":"application/x-www-form-urlencoded","Cookie":"sessionid"}
conn = http.client.HTTPConnection("localhost")
conn.request("POST","/agileone/index.php/common/login/",param,header)
param = "type=Requirement&importance=medium&scope=1&headline=" \
    "Headline from Python-12346&content="\
    "Content from Python=12346&processresult="
#构建请求头，必须将Cookie=sessionid的状态附加在请求中
header = {"Content-type":"application/x-www-form-urlencoded","Cookie":"sessionid"}
conn = http.client.HTTPConnection("localhost")
conn.request("POST","/agileone/index.php/proposal/add",param.encode(),header)
response = conn.getresponse().read()#获取响应内容
print(response.decode())#如果返回时一个数字，表名新增成功，返回的是新需求提案的编号